app.controller('ApiListCtrl', function ($scope, ajax, $modal, toaster) {

	var updater = new Req.PUT({ resource: $scope.resource });

	$scope.reload = $scope.page.loader('apiconf/{pageIndex}/{pageSize}/page');
	$scope.$on('pageIndex', function (event, p) { $scope.reload(p, $scope.queryMap); });
	$scope.reload(1);
	$scope.queryMap = {};
	$scope.query = function () { $scope.reload(1, $scope.queryMap); };

	// 新增、更新
	$scope.write = function (size, current_data, submit_type) {
		$scope.current_data = angular.copy(current_data);
		var modalInstance = $modal.open({
			templateUrl: 'template/system/api/writeModal.html?v=2a01c4ad3c',
			controller: 'ModalCtrl',
			size: size,
			resolve: {
				param: function () {
					return {
						"data": $scope.current_data,
						"type": submit_type
					};
				}
			}
		});
		modalInstance.result.then(function (param) {
			if (param.type == 'update') {
				updater.fields = param.data;
				updater.id = param.data.id;
				updater.resource = 'apiconf/update';
				$scope.page.mod(updater, $scope.reload, $scope.queryMap);
			}
		});
	};

});
